﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Data;

namespace AbetEvaluation.Business
{
	public partial class Taken : Component
	{
		public Taken()
		{
			InitializeComponent();
		}

		public Taken(IContainer container)
		{
			container.Add(this);

			InitializeComponent();
		}

		public static DataTable GetAllTaken()
		{
			Data.DataSet1TableAdapters.abet_TakenTableAdapter adapter = new Data.DataSet1TableAdapters.abet_TakenTableAdapter();
			Data.DataSet1.abet_TakenDataTable table = adapter.GetAllTaken();
			return table;
		}

		public static int InsertTake(Take t)
		{
			Data.DataSet1TableAdapters.abet_TakenTableAdapter adapter = new Data.DataSet1TableAdapters.abet_TakenTableAdapter();
			int result = adapter.InsertTake(t.ID, t.UserName, t.OutcomeID, t.Grade);
			return result;
		}

		public static int GetTakenCount(Guid outcomeID)
		{
			Data.DataSet1TableAdapters.abet_TakenTableAdapter adapter = new Data.DataSet1TableAdapters.abet_TakenTableAdapter();
			int result = (int)adapter.GetTakenCount(outcomeID);
			return result;
		}

		public static Decimal GetAverageGrade(Guid outcomeID)
		{
			Data.DataSet1TableAdapters.abet_TakenTableAdapter adapter = new Data.DataSet1TableAdapters.abet_TakenTableAdapter();
			Decimal result = (Decimal)adapter.GetAverageGrade(outcomeID);
			return result;
		}

		public static Decimal GetGrade(Guid takenID)
		{
			Data.DataSet1TableAdapters.abet_TakenTableAdapter adapter = new Data.DataSet1TableAdapters.abet_TakenTableAdapter();
			Decimal result = (Decimal)adapter.GetGrade(takenID);
			return result;
		}

		public static int UpdateGrade(Guid takenID, Decimal grade)
		{
			Data.DataSet1TableAdapters.abet_TakenTableAdapter adapter = new Data.DataSet1TableAdapters.abet_TakenTableAdapter();
			int result = adapter.UpdateGrade(grade, takenID);
			return result;
		}

		public static int DeleteTake(Take t)
		{
			//delete results for take.
			Data.DataSet1TableAdapters.abet_ResultsTableAdapter resultsAdapter = new Data.DataSet1TableAdapters.abet_ResultsTableAdapter();
			int temp = resultsAdapter.DeleteResultsByTakenID(t.ID);

			//delete take.
			Data.DataSet1TableAdapters.abet_TakenTableAdapter takenAdapter = new Data.DataSet1TableAdapters.abet_TakenTableAdapter();
			int result = (int)takenAdapter.DeleteTake(t.ID);
			return result;
		}
	}
}
